/**
 * 
 */
package mdb.com.vn.web.beans;

import java.io.Serializable;
import java.math.BigDecimal;

import javax.annotation.PostConstruct;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;
import javax.faces.bean.ViewScoped;

import mdb.com.vn.services.MDBServices;
import mdb.com.vn.utils.NumberUtils;

import org.primefaces.model.StreamedContent;
import org.primefaces.model.chart.PieChartModel;

/**
 * @author tu.dod
 *
 */
@ManagedBean(name="chartBeans")
@ViewScoped
public class ChartBeans implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private PieChartModel pieModel;
	private StreamedContent chart;  
	/**
	 * @return the pieModel
	 * @throws IOException 
	 */
	
	private BigDecimal fdSumAmount;
	private BigDecimal csSumAmount;
	private BigDecimal fdCSSumAmount;
	private BigDecimal loansSumAmount;
	private int allLuckyDraw;
	
	@ManagedProperty("#{mdbServices}")
	private MDBServices mdbServices;
	
	@PostConstruct
	public void init(){
		int deno20k = mdbServices.countSCByDenomination(NumberUtils.VND20000);
		int deno50k = mdbServices.countSCByDenomination(NumberUtils.VND50000);
		int deno100k = mdbServices.countSCByDenomination(NumberUtils.VND100000);
		int deno200k = mdbServices.countSCByDenomination(NumberUtils.VND200000);
		int deno500k = mdbServices.countSCByDenomination(NumberUtils.VND500000);
		 int totalThanks = mdbServices.countThanksScCard();
		 fdSumAmount = mdbServices.sumFDAmount();
		 csSumAmount = mdbServices.sumSAAmount();
		 fdCSSumAmount = mdbServices.sumFDCAAmount();
		 allLuckyDraw = mdbServices.countAllLuckyDraw();
		 loansSumAmount = mdbServices.sumLoansAmount();
		
		 pieModel = new PieChartModel();  
	        pieModel.set("Thẻ 20.000VND", deno20k);  
	        pieModel.set("Thẻ 50.000VND", deno50k);  
	        pieModel.set("Thẻ 100.000VND", deno100k);  
	        pieModel.set("Thẻ 200.000VND", deno200k);  
	        pieModel.set("Thẻ 500.000VND", deno500k);  
	        pieModel.set("Thẻ cảm ơn (0VND)", totalThanks);
 
	}
	public PieChartModel getPieModel() {
		return pieModel;
	}
	/**
	 * @return the chart
	 */
	public StreamedContent getChart() {
		return chart;
	}
	/**
	 * @param mdbServices the mdbServices to set
	 */
	public void setMdbServices(MDBServices mdbServices) {
		this.mdbServices = mdbServices;
	}
	/**
	 * @return the fdSumAmount
	 */
	public BigDecimal getFdSumAmount() {
		return fdSumAmount;
	}
	/**
	 * @param fdSumAmount the fdSumAmount to set
	 */
	public void setFdSumAmount(BigDecimal fdSumAmount) {
		this.fdSumAmount = fdSumAmount;
	}
	/**
	 * @return the csSumAmount
	 */
	public BigDecimal getCsSumAmount() {
		return csSumAmount;
	}
	/**
	 * @param csSumAmount the csSumAmount to set
	 */
	public void setCsSumAmount(BigDecimal csSumAmount) {
		this.csSumAmount = csSumAmount;
	}
	/**
	 * @return the fdCSSumAmount
	 */
	public BigDecimal getFdCSSumAmount() {
		return fdCSSumAmount;
	}
	/**
	 * @param fdCSSumAmount the fdCSSumAmount to set
	 */
	public void setFdCSSumAmount(BigDecimal fdCSSumAmount) {
		this.fdCSSumAmount = fdCSSumAmount;
	}
	/**
	 * @return the allLuckyDraw
	 */
	public int getAllLuckyDraw() {
		return allLuckyDraw;
	}
	/**
	 * @param allLuckyDraw the allLuckyDraw to set
	 */
	public void setAllLuckyDraw(int allLuckyDraw) {
		this.allLuckyDraw = allLuckyDraw;
	}
	/**
	 * @return the loansSumAmount
	 */
	public BigDecimal getLoansSumAmount() {
		return loansSumAmount;
	}
	/**
	 * @param loansSumAmount the loansSumAmount to set
	 */
	public void setLoansSumAmount(BigDecimal loansSumAmount) {
		this.loansSumAmount = loansSumAmount;
	}  
	
	 
}
